package com.tms.app.tms.test.utils;

import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;

/**
 * Created by Administrator on 2017/10/25 0025.
 */

public class ServiceUtil {
    //"com.tms.app.tms.Service.test.service.AlarmServer"
    public static void  startServiceIfDead(Context context,Class<?> tClass){
        boolean isLive=false;
        ActivityManager manager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningServiceInfo service :manager.getRunningServices(Integer.MAX_VALUE)) {
            if(tClass.getName().equals(service.service.getClassName()))
            {
                isLive = true;
            }
        }
        if (!isLive) {
            Intent i = new Intent(context, tClass);
            context.startService(i);
        }
    }

}
